package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.Article;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.GetPriceService;
import com.qf.lanzhou.blog.api.service.impl.GetPriceServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 是柠檬甜
 * @ClassName GetPriceStatus
 * @description 获取用户点赞状态
 * @date 2020/12/21 19:11
 * @modifier 是柠檬甜
 * @date 2020-12-21 19:11
 * @Version V1.0
 */
@WebServlet("/getPriceStatus.do")
public class GetPriceStatusServlet extends BaseServletPost {
    private GetPriceService getPriceService = new GetPriceServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收参数
        System.out.println("点赞服务器连接成功，dopost");
        String articleId = req.getParameter("articleId");
        Long article = Long.decode(articleId);
        System.out.println(article+"大头鹏");
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        System.out.println("日志记录");
        //调用业务逻辑层
        Long i = getPriceService.getPriceStatus(article, user.getId());
        //返回给前端
        successResultWrite(i,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
